<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Helper extends CI_Controller {

	public function index()
	{		
		
	}
	
	public function firstCategoryName() {
		$this->load->model('Orderedcategories_model');
		
		$firstCategoryName = $this->Orderedcategories_model->getFirstCategoryName();
		
		echo $firstCategoryName;
	}
	
	public function firstCategoryProducts() {

		//modell
		$this->load->model('Products_model');
		$this->load->model('Orderedcategories_model');
		
		$firstCategoryId = $this->Orderedcategories_model->getFirstCategoryID();
		
		$products = $this->Products_model->categorizedProductsJSON($firstCategoryId);
		
		echo json_encode($products);
	}
	
	public function products() {

		//modell
		$this->load->model('Products_model');
		
		//$this->load->library('KLogger');
		//$log = new KLogger("logooo.txt" , KLogger::DEBUG);
		//$log->LogDebug("post parameter: " + $this->input->post('categoryID'));
		
		if($this->input->post('categoryID')) {
			//$log->LogDebug("filtered prod");
			$products = $this->Products_model->categorizedProducts($this->input->post('categoryID'));
			//$products = $this->Products_model->productsJSON();
		} else {
			//$log->LogDebug("all");
			$products = $this->Products_model->allProducts();
		}
		
		echo json_encode($products);
	}
	
}
